﻿@using System.Collections
<div class="collection-editor">
    @if(Model!=null){
        var e = (IEnumerable) Model;
        var eType = e.TryGetGenericType();
       
        var c = (ICollection) e;
        
        string oldPrefix = ViewData.TemplateInfo.HtmlFieldPrefix;
        int index = 0;
        ViewData.TemplateInfo.HtmlFieldPrefix = String.Empty;
        
       
    foreach(object item in e)
        {
            string fieldName = string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}[{1}]", oldPrefix, index++);
            if (c != null) {
                ViewContext.Writer.Write(Html.CheckBox(fieldName,true,"excluder"));
            }
            ViewContext.Writer.Write(Html.DisplayFor(m=>item,null,fieldName));
        }
       
        ViewData.TemplateInfo.HtmlFieldPrefix = oldPrefix;
        if(c!=null)
        {
            @: <input type="button" class="collection-add" id="@ViewData.TemplateInfo.HtmlFieldPrefix-Add" value="Add"/>
        }
            
    }
     
</div>